Dim objDTE
Dim objCommand
Dim objTb

On Error Resume Next

Set objDTE = CreateObject("VisualStudio.DTE.7.1")
If objDTE Is Nothing Then
    MsgBox "Couldn't find VS 2003"
Else

    Set objCommand = objDTE.Commands.Item("SampleCAI.CoAddIn.Configure")
    If objCommand Is Nothing Then
        MsgBox "The Configure command has already been deleted."
    Else
      objCommand.AddControl(objDTE.CommandBars.Item("Tools"))
      objCommand.Delete
    End If

    Set objCommand = objDTE.Commands.Item("SampleCAI.CoAddIn.SayHello")
    If objCommand Is Nothing Then
        MsgBox "The SayHello command has already been deleted."
    Else
      objCommand.AddControl(objDTE.CommandBars.Item("Tools"))
      objCommand.Delete
    End If

    Set objTb = objDTE.CommandBars.Item("SampleCAI")
    If objTb Is Nothing Then
        MsgBox "No (permanent) command bar named SampleCAI."
    Else
        objDTE.Commands.RemoveCommandBar(objTb)
        objTb.Delete
        set objTb = Nothing
    End If

    objDTE.Quit
    set objDTE = Nothing

End If

Set objDTE = CreateObject("VisualStudio.DTE.8.0")
If objDTE Is Nothing Then
    MsgBox "Couldn't find VS 2005"
Else

    Set objCommand = objDTE.Commands.Item("SampleCAI.CoAddIn.Configure")
    If objCommand Is Nothing Then
        MsgBox "The Configure command has already been deleted."
    Else
      'objCommand.AddControl(objDTE.CommandBars.Item("Tools"))
      objCommand.Delete
    End If

    Set objCommand = objDTE.Commands.Item("SampleCAI.CoAddIn.SayHello")
    If objCommand Is Nothing Then
        MsgBox "The SayHello command has already been deleted."
    Else
      'objCommand.AddControl(objDTE.CommandBars.Item("Tools"))
      objCommand.Delete
    End If

    Set objTb = objDTE.CommandBars.Item("SampleCAI")
    If objTb Is Nothing Then
        MsgBox "No (permanent) command bar named SampleCAI."
    Else
        objDTE.Commands.RemoveCommandBar(objTb)
        objTb.Delete
        set objTb = Nothing
    End If

    objDTE.Quit
    set objDTE = Nothing

End If

Set objDTE = CreateObject("VisualStudio.DTE.9.0")
If objDTE Is Nothing Then
    MsgBox "Couldn't find VS 2008"
Else

    Set objCommand = objDTE.Commands.Item("SampleCAI.CoAddIn.Configure")
    If objCommand Is Nothing Then
        MsgBox "The Configure command has already been deleted."
    Else
      'objCommand.AddControl(objDTE.CommandBars.Item("Tools"))
      objCommand.Delete
    End If

    Set objCommand = objDTE.Commands.Item("SampleCAI.CoAddIn.SayHello")
    If objCommand Is Nothing Then
        MsgBox "The SayHello command has already been deleted."
    Else
      'objCommand.AddControl(objDTE.CommandBars.Item("Tools"))
      objCommand.Delete
    End If

    Set objTb = objDTE.CommandBars.Item("SampleCAI")
    If objTb Is Nothing Then
        MsgBox "No (permanent) command bar named SampleCAI."
    Else
        objDTE.Commands.RemoveCommandBar(objTb)
        objTb.Delete
        set objTb = Nothing
    End If

    objDTE.Quit
    set objDTE = Nothing

End If

